import Vue from 'vue'
import Router from 'vue-router'
import store from '@/common/store/index.js'

Vue.use(Router)
const router = new Router({
  routes: [{
      path: '/',
      component: resolve => require(['../view/user_login.vue'], resolve),
      meta: {
        requireAuth: false
      }
    },
    {
      path: '/user_login',
      component: resolve => require(['../view/user_login.vue'], resolve),
      meta: {
        requireAuth: false
      }
    },
    {
      path: '/index',
      component: resolve => require(['../view/index.vue'], resolve),
      meta: {
        requireAuth: false
      },
      children: [],
    },
    {
      path: '/frame',
      component: resolve => require(['../view/frame.vue'], resolve),
      name: 'frame',
    },
    {
      path: '/forgetPwd',
      component: resolve => require(['../view/forget_pwd.vue'], resolve),
      name: '忘记密码',
    },
    {
      path: '/otherLogin',
      component: resolve => require(['../view/other_login.vue'], resolve),
      name: '第三方绑定手机号',
    },
    {
      path: '/lecture',
      component: resolve => require(['../view/lecture.vue'], resolve),
      name: '授课',
    },
    {
      path: '/prepareLessons2',
      component: resolve => require(['../view/prepare_lessons.vue'], resolve),
      name: '备课',
    },
    {
      path: '/courseList',
      component: resolve => require(['../view/course/index.vue'], resolve),
      name: '备课',
    },
    {
      path: '/courseCollect',
      component: resolve => require(['../view/course/collect.vue'], resolve),
      name: '我的收藏',
    },
    {
      path : '/search_content',
      component: resolve => require(['../view/course/search_content.vue'], resolve),
      name : '搜索界面'
    },
    {
      path: '/courseDetail',
      component: resolve => require(['../view/course/detail.vue'], resolve),
      name: '查看',
    },
    {
      path: '/courseView',
      component: resolve => require(['../view/course/view.vue'], resolve),
      name: '查看',
    },
    {
      path: '/courseView2',
      component: resolve => require(['../view/course/view2.vue'], resolve),
      name: '查看',
    },
    {
      path: '/courseMy',
      component: resolve => require(['../view/course/my.vue'], resolve),
      name: '我的课程',
    },
    {
      path: '/msglist',
      component: resolve => require(['../view/msglist.vue'], resolve),
      name: '消息中心',
    },
    {
      path: '/setting',
      component: resolve => require(['../view/my/setting.vue'], resolve),
      name: '我的设置',
    },
    {
      path: '/feedback',
      component: resolve => require(['../view/feedback.vue'], resolve),
      name: '建议反馈',
    },
    {
      path: '/train',
      component: resolve => require(['../view/train/index.vue'], resolve),
      name: '培训',
    },
    {
      path: '/trainlist',
      component: resolve => require(['../view/train/list.vue'], resolve),
      name: '全部课程',
    }, {
      // 精品课程
      path: '/trainlist2',
      component: resolve => require(['../view/train/list2.vue'], resolve),
      name: '全部课程',
    },
    {
      path: '/process',
      component: resolve => require(['../view/train/process.vue'], resolve),
      name: '学习进度',
    },
    // 课程详情
    {
      path: '/trainDetail',
      component: resolve => require(['../view/train/detail.vue'], resolve),
      name: '课程详情',
    },
    // 课程详情
    {
      path: '/classPlay',
      component: resolve => require(['../view/train/classPlay.vue'], resolve),
      name: '附件播放',
    },
    {
      path: '/trainstudy',
      component: resolve => require(['../view/train/study.vue'], resolve),
      name: '学习进度',
    },
    {
      path: '/trainpay',
      component: resolve => require(['../view/train/pay.vue'], resolve),
      name: '付费报名',
    },

    {
      path: '/trainpay2',
      component: resolve => require(['../view/train/pay2.vue'], resolve),
      name: '付费报名',
    },
    {
      path: '/trainplay',
      component: resolve => require(['../view/train/play.vue'], resolve),
      name: '视频播放',
    },
    {
      path: '/test',
      component: resolve => require(['../view/test/index.vue'], resolve),
      name: '声律启蒙考试练习',
    },
    {
      path: '/test1',
      component: resolve => require(['../view/test/test1.vue'], resolve),
      name: '声律启蒙考试练习',
    },
    {
      path: '/test2',
      component: resolve => require(['../view/test/test2.vue'], resolve),
      name: '得分',
    },
    {
      path: '/test3',
      component: resolve => require(['../view/test/test3.vue'], resolve),
      name: '答题卡',
    },


    {
      path: '/recycle',
      component: resolve => require(['../view/recycle.vue'], resolve),
      name: '回收站',
    },
    {
      path: '/lessonsList',
      component: resolve => require(['../view/lessons/index.vue'], resolve),
      name: '课程资源',
    },
    {
      path: '/lessonsadd',
      component: resolve => require(['../view/lessons/add.vue'], resolve),
      name: '上传',
    },
    {
      path: '/selectChapter',
      component: resolve => require(['../view/lessons/select.vue'], resolve),
      name: '上传',
    },

    {
      path: '/selectChapter3',
      component: resolve => require(['../view/lessons/select3.vue'], resolve),
      name: '上传',
    },

    {
      path: '/selectChapter2',
      component: resolve => require(['../view/lessons/select2.vue'], resolve),
      name: '上传',
    },

    {
      path: '/collectChapter',
      component: resolve => require(['../view/lessons/collect.vue'], resolve),
      name: '上传',
    },
    {
      path: '/seeziyuan',
      component: resolve => require(['../view/lessons/seeziyuan.vue'], resolve),
      name: '查看资源',
    },
    {
      path: '/bkblist',
      component: resolve => require(['../view/bkb/index.vue'], resolve),
      name: '备课包',
    },
    {
      path: '/bkbshare',
      component: resolve => require(['../view/bkb/share.vue'], resolve),
      name: '我的分享',
    },
    {
      path: '/shareall',
      component: resolve => require(['../view/bkb/shareall.vue'], resolve),
      name: '我的分享',
    },
    {
      path: '/bkblist2',
      component: resolve => require(['../view/bkb/index2.vue'], resolve),
      name: '备课包',
    },
    {
      path: '/ykt',
      component: resolve => require(['../view/bkb/ykt.vue'], resolve),
      name: '中华经典云课堂',
    },
    {
      path: '/classDetail',
      component: resolve => require(['../view/bkb/classDetail.vue'], resolve),
      name: '云课堂详情',
    },
    {
      path: '/my',
      component: resolve => require(['../view/my/my.vue'], resolve),
      name: '我的',
    },
    {
      path: '/share',
      component: resolve => require(['../view/share.vue'], resolve),
      name: '我的',
    },
    {
      path: '/profile',
      component: resolve => require(['../view/my/profile.vue'], resolve),
      name: '我的',
    },
    {
      path: '/attendClass',
      component: resolve => require(['../view/frame.vue'], resolve),
      name: '上课',
    },
    {
      path: '/students',
      component: resolve => require(['../view/student/index.vue'], resolve),
      name: '学生',
    },
    {
      path: '/resource',
      component: resolve => require(['../view/resource/index.vue'], resolve),
      name: '资源',
    },
    {
      path: '/collect',
      component: resolve => require(['../view/resource.vue'], resolve),
      name: '资源',
    },
    {
      path: '/space',
      component: resolve => require(['../view/lessons/space.vue'], resolve),
      name: '资源',
    }


  ]
})
// 点击当前路由时
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

// 判断是否需要登录权限 以及是否登录
router.beforeEach((to, from, next) => {
  if (to.matched.some(res => res.meta.requireAuth)) { // 判断是否需要登录权限
    if (localStorage.getItem('token')) { // 判断是否登录
      next()
    } else {
      next({
        path: '/',
        query: {
          redirect: to.fullPath
        }
      })
    }
  } else {
    next()
  }
})

export default router
